import Vue from 'vue'
import Vuex from 'vuex'
import student from './student'
import { getSession,removeSession } from '../service'

Vue.use(Vuex);

export default new Vuex.Store({
    modules:{
        student
        
    },
    state:{
        count:0,
        user:null,
        functions:[]
    },
    getters:{
        myCount(state){
            console.log("getter")
            return "$" + state.count
        }
    },
    mutations:{
        increment(state){
            state.count++;
        },
        setLoginUser(state,user){
            state.user = user;
        },
        setFunctions(state,functions){
            state.functions = functions;
        }
    },
    actions:{
        async setLoginUser(context){
            let data = await getSession();
            console.log("setLoginUser",data);
            context.commit("setLoginUser",data);
        },
        async logout(context){
            await removeSession();
            context.commit("setLoginUser",null);
        }
    }
})
